package com.flxz.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flxz.common.annotation.Log;
import com.flxz.common.core.controller.BaseController;
import com.flxz.common.core.domain.AjaxResult;
import com.flxz.common.enums.BusinessType;
import com.flxz.manage.domain.ManageUserExpense;
import com.flxz.manage.service.IUserExpenseService;
import com.flxz.common.utils.poi.ExcelUtil;
import com.flxz.common.core.page.TableDataInfo;

/**
 * 用户支出（管理员）Controller
 * 
 * @author fl
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/manage/expenseAdmin")
public class UserExpenseAdminController extends BaseController
{
    @Autowired
    private IUserExpenseService userExpenseService;

    /**
     * 查询用户支出（管理员）列表
     */
    @PreAuthorize("@ss.hasPermi('manage:expenseAdmin:list')")
    @GetMapping("/list")
    public TableDataInfo list(ManageUserExpense userExpense)
    {
        startPage();
        List<ManageUserExpense> list = userExpenseService.selectUserExpenseList(userExpense);
        return getDataTable(list);
    }

    /**
     * 导出用户支出（管理员）列表
     */
    @PreAuthorize("@ss.hasPermi('manage:expenseAdmin:export')")
    @Log(title = "用户支出（管理员）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ManageUserExpense userExpense)
    {
        List<ManageUserExpense> list = userExpenseService.selectUserExpenseList(userExpense);
        ExcelUtil<ManageUserExpense> util = new ExcelUtil<ManageUserExpense>(ManageUserExpense.class);
        util.exportExcel(response, list, "用户支出（管理员）数据");
    }

    /**
     * 获取用户支出（管理员）详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:expenseAdmin:query')")
    @GetMapping(value = "/{expenseId}")
    public AjaxResult getInfo(@PathVariable("expenseId") Long expenseId)
    {
        return success(userExpenseService.selectUserExpenseByExpenseId(expenseId));
    }

    /**
     * 新增用户支出（管理员）
     */
    @PreAuthorize("@ss.hasPermi('manage:expenseAdmin:add')")
    @Log(title = "用户支出（管理员）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManageUserExpense userExpense)
    {
        return toAjax(userExpenseService.insertUserExpense(userExpense));
    }

    /**
     * 修改用户支出（管理员）
     */
    @PreAuthorize("@ss.hasPermi('manage:expenseAdmin:edit')")
    @Log(title = "用户支出（管理员）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManageUserExpense userExpense)
    {
        return toAjax(userExpenseService.updateUserExpense(userExpense));
    }

    /**
     * 删除用户支出（管理员）
     */
    @PreAuthorize("@ss.hasPermi('manage:expenseAdmin:remove')")
    @Log(title = "用户支出（管理员）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expenseIds}")
    public AjaxResult remove(@PathVariable Long[] expenseIds)
    {
        return toAjax(userExpenseService.deleteUserExpenseByExpenseIds(expenseIds));
    }
}
